<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>vue的多个元素或组件的过渡动画</title>
  <script src="./js/vue2.js"></script>
  <script src="./js/velocity.js"></script>
  <style>
    .v-enter,
    .v-leave-to{
      opacity:0;
    }
    .v-enter-active,
    .v-leave-active{
      transition: opacity 1s;;
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- mode属性可以定义显示与隐藏方式  out-in是先隐藏再显示-->
    <transition mode="out-in">
      <!-- 由于vue会尽可能的复用dom，所以导致动画效果不生效，此时需要添加 key -->
      <!-- <div v-if="show" key="hello">Hello world</div>
      <div v-else key="bye">Bye world</div> -->

      <!-- 组件 -->
      <!-- <child v-if="show"></child>
      <child-one v-else></child-one> -->

      <!-- 动态组件 -->
      <component :is="type"></component>

    </transition>

    <button @click="handleClick">toggle</button>
  </div>
</body>
</html>
<script>
  // 组件
  Vue.component('child', {
    template: `
      <div>child</div>
    `,
  });
  Vue.component('child-one', {
    template: `
      <div>child-one</div>
    `,
  });

  var app = new Vue({
    el:'#app',
    data:{
      // show:true,
      type:'child',
    },
    methods: {
      handleClick: function(){
        // this.show = !this.show;
        this.type = (this.type==='child'?'child-one':'child');
      },
    }
  });
</script>